#include "Movie.h"

bool existInStringList(ListString list, std::string value){
	for(ListString::iterator it=list.begin();it!=list.end();it++){
		if((*it).compare(value)==0){
			return true;
		}
	}
	return false;
}

Movie::Movie(void)
{
}

int Movie::length(){
	return 0;
}

std::string Movie::getLabel(){
	return label;
}

void Movie::setLabel(std::string lbl){
	label=lbl;
}

MapTags Movie::getTags(){
	return tags;
}

bool Movie::existTagKey(std::string key){
	return !(getTag(key).empty());
}

bool Movie::existTagValue(std::string value){
	return !(getTagKey(value).empty());
}


void Movie::addTag(std::string key, std::string value){
	PairMapTags ret;
	ListString addNew ( 1, value );
	ret = tags.insert( std::pair<std::string,ListString>(key,addNew) );
	if( ret.second==false ){
		ListString list = ret.first->second;
		list.push_front(value);
	}
}

ListString Movie::getTag(std::string key){
	MapTags::iterator it = tags.find(key);
	if(it==tags.end()){
		ListString ret;
		return ret;
	}
	return it->second;
}

std::string Movie::getTagKey(std::string value){
	for(MapTags::iterator it=tags.begin();it!=tags.end();it++){
		if(existInStringList(it->second,value)){
			return it->first;
		}
	}
	std::string ret;
	return ret;
}



File::TypeFile Movie::type(void){
	return File::MOVIE;
}

Movie::~Movie(void)
{
}
